//
//  MyDetailTableViewController.swift
//  股票框架
//
//  Created by 李小骥 on 2017/10/19.
//  Copyright © 2017年 李小骥. All rights reserved.
//

import UIKit
import Photos
import MediaPlayer
import AVFoundation
import AssetsLibrary
import ImageIO
import CoreLocation
import Alamofire
import RxSwift
import RxCocoa
class MyDetailTableViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource,UIAlertViewDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate{
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
//        switch pickerView.tag 类决定返回值
        switch pickerView.tag {
        case 0:
            return 1
        default://就是 tag 是1
            return 2
        }
    }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        //        switch pickerView.tag 类决定返回值
        switch pickerView.tag {
        case 0:
            return genderArray.count
        default://就是 tag 是1
            switch component{
            case 0:
                return provincesAndCitiesArray.count
            default://此处只有省市，因此只有0和1两排，default 就是1号排，显示各省的城市数量
                let province = provincesAndCitiesArray[provincesIndex]
                let provinceArray = province["Cities"] as! Array<Dictionary<String,Any>>
                return provinceArray.count
            }
        }
    }
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        switch pickerView.tag {
        case 0://只有1排不涉及component
            return genderArray[row]
        default://就是 tag 是1，是城市
            switch component{
            case 0://省
                let province = provincesAndCitiesArray[row]
                return (province["State"] as! String)
            default://此处只有省市，因此只有0和1两排，default 就是1号排，显示各省的城市数量
                let province = provincesAndCitiesArray[provincesIndex]
                let provinceArray = province["Cities"] as! Array<Dictionary<String,Any>>
                let city = provinceArray[row]
                return (city["city"] as! String)
            }
        }
    }
//    mark 还没有做完，有可能直接和alertview的确定按钮绑定，也可能是需要设置临时变量存储选择的数值，点击确定时使用 getValue 方法赋值
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        switch pickerView.tag {
        case 0:
            genderAlertController.textFields?.first?.text = genderArray[row]
        default://就是 tag 是1
            switch component{
            case 0:
                provincesIndex = row
                cityIndex = 0
                pickerView.reloadComponent(1)
                pickerView.selectRow(0, inComponent: 1, animated: true)
                let province = provincesAndCitiesArray[provincesIndex]
                let provinceName = province["State"] as! String
                let provinceArray = province["Cities"] as! Array<Dictionary<String,Any>>
                let city = provinceArray[cityIndex]
                let cityName = city["city"] as! String
                areaAlertController.textFields?.first?.text = provinceName + cityName
            default://此处只有省市，因此只有0和1两排，default 就是1号排，显示各省的城市数量
                cityIndex = row
                let province = provincesAndCitiesArray[provincesIndex]
                let provinceName = province["State"] as! String
                let provinceArray = province["Cities"] as! Array<Dictionary<String,Any>>
                let city = provinceArray[cityIndex]
                let cityName = city["city"] as! String
                areaAlertController.textFields?.first?.text = provinceName + cityName
            }
        }
    }
//    func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
//        switch pickerView.tag {
//        case 0:
//            return 100
//        default://就是 tag 是1
//            switch component{
//            case 0:
//                return 70
//            default:
//                return 70
//            }
//        }
//    }
    let genderArrayPath = Bundle.main.path(forResource: "gender", ofType:"plist")
    var genderArray:[String] {
        return NSArray(contentsOfFile: genderArrayPath!) as! Array<String>
    }
  var genderAlertController=UIAlertController()
    var areaAlertController=UIAlertController()
    let provincesAndCitiesArrayPath = Bundle.main.path(forResource: "ProvincesAndCities", ofType:"plist")
    var provincesAndCitiesArray:Array<Dictionary<String,Any>> {
        return NSArray(contentsOfFile: provincesAndCitiesArrayPath!) as! Array<Dictionary<String,Any>>
    }
    var provincesIndex = 0 //表示选取根数组的第几个省的索引
    var cityIndex = 0
    var pickerView = UIPickerView()
    var datePicker = UIDatePicker()
//    var myDetailModelTemp:MyDetailModel = MyDetailModel()
    var myDetailModel:MyDetailModel = MyDetailModel(){
        didSet{
            tableView.reloadData()
        }
    }
    var cellLabelGroups:[[String]]{
        get{
            
            let cellLabelGroup0:[String] = ["头像","昵称","性别"," QQ"]
            let cellLabelGroup1:[String] = ["生日","地区"]
            return [cellLabelGroup0,cellLabelGroup1]
        }
    }
    let rightLabelPlaceholder = "未填写"
    override func viewDidLoad() {
        super.viewDidLoad()
        setTableView()
        setPickerView()
        setDatePicker()
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem
    }
    func setDatePicker(){
        datePicker = UIDatePicker(frame: CGRect(center: tableView.center, size: CGSize(width: 240, height: 160)))
        datePicker.datePickerMode = .date
        datePicker.locale = Locale(identifier: "zh_CN")
//        datePicker.addTarget(self, action: #selector(datechanged(_:UITextField,_:UIDatePicker)), for: .valueChanged)
    }
//    @objc func datechanged(_ textField: UITextField,_ sender:UIDatePicker){
//
//    }
    func updateNicknameAlert(cell:MyDetailTableViewCell){
//        textAlertController.textFields?.first?.inputView = pickerView
        let alertController = UIAlertController(title: "输入昵称", message: nil, preferredStyle: .alert)
        alertController.addTextField { (text) in
            
        }
        alertController.textFields?.first?.keyboardType = .default
        weak var weakSelf:MyDetailTableViewController? = self
        let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
            weakSelf?.myDetailModel.nickName = (alertController.textFields?.first?.text)!
// 给 nickname 写 willset：把修改信息发给 lcode属性
//            通知临时模型，页面离开时候比较两个模型，不同的话就对应上传
//            weakSelf?.myDetailModelTemp.nickName = (weakSelf?.myDetailModel.nickName)!
            weakSelf?.setCellRightLabel(property: (alertController.textFields?.first?.text)!, cell: cell)
        }
        let cancelAction = UIAlertAction(title: "取消", style: .default) { (action) in
        }
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        present(alertController, animated: true, completion: nil)
    }
    func updateGenderAlert(cell:MyDetailTableViewCell){
        let alertController = UIAlertController(title: "选择性别", message: nil, preferredStyle: .alert)
        alertController.addTextField { (text) in
            
        }
        alertController.textFields?.first?.inputView = pickerView
//        textAlertController.textFields?.first?.keyboardType = .default
        weak var weakSelf:MyDetailTableViewController? = self
        let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
            var rawValue = "3"
            switch (alertController.textFields?.first?.text)!{
            case "男":rawValue = "1"
            case "女":rawValue = "2"
            default:rawValue = "3"
            }
            weakSelf?.myDetailModel.gender = Gender(rawValue: rawValue)
            
            // 给 nickname 写 willset：把修改信息发给 lcode属性
            //            通知临时模型，页面离开时候比较两个模型，不同的话就对应上传
//            weakSelf?.myDetailModelTemp.gender = weakSelf?.myDetailModel.gender
            weakSelf?.setCellRightLabel(property: (alertController.textFields?.first?.text)!, cell: cell)
        }
        let cancelAction = UIAlertAction(title: "取消", style: .default) { (action) in
        }
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        genderAlertController = alertController
        present(alertController, animated: true, completion: nil)
    }
    func updateQQAlert(cell:MyDetailTableViewCell){
        //        textAlertController.textFields?.first?.inputView = pickerView
        let alertController = UIAlertController(title: "输入QQ", message: nil, preferredStyle: .alert)
        alertController.addTextField { (text) in
            
        }
        alertController.textFields?.first?.keyboardType = .numberPad
        weak var weakSelf:MyDetailTableViewController? = self
        let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
            weakSelf?.myDetailModel.qq = (alertController.textFields?.first?.text)!
            // 给 nickname 写 willset：把修改信息发给 lcode属性
            //            通知临时模型，页面离开时候比较两个模型，不同的话就对应上传
//            weakSelf?.myDetailModelTemp.qq = (weakSelf?.myDetailModel.qq)!
            weakSelf?.setCellRightLabel(property: (alertController.textFields?.first?.text)!, cell: cell)
        }
        let cancelAction = UIAlertAction(title: "取消", style: .default) { (action) in
        }
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        present(alertController, animated: true, completion: nil)
    }
    func updateBirthdayAlert(cell:MyDetailTableViewCell){
        let alertController = UIAlertController(title: "设置生日", message: nil, preferredStyle: .alert)
        alertController.addTextField { (text) in
        }
        alertController.textFields?.first?.inputView = datePicker
        datePicker.rx.date.asObservable().subscribe(onNext: { (date) in
            let formatter = DateFormatter()
            formatter.locale = Locale(identifier: "zh_CN")
            formatter.dateFormat = "yyyy年MM月dd日"
            alertController.textFields?.first?.text = formatter.string(from: date)
        }, onError: { (error) in
            print(error)
        }, onCompleted: {
            print("compate")
        }) {
            print("dispose")
        }
        //        textAlertController.textFields?.first?.keyboardType = .default
        weak var weakSelf:MyDetailTableViewController? = self
        let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
            let formatter = DateFormatter()
            formatter.locale = Locale(identifier: "zh_CN")
            formatter.dateFormat = "yyyyMMdd"
            let string = formatter.string(from: (weakSelf?.datePicker.date)!)
            weakSelf?.myDetailModel.birthday = Birthday(birthDayString: string)
            // 给 nickname 写 willset：把修改信息发给 lcode属性
            //            通知临时模型，页面离开时候比较两个模型，不同的话就对应上传
//            weakSelf?.myDetailModelTemp.birthday = (weakSelf?.myDetailModel.birthday)!
            weakSelf?.setCellRightLabel(property: (alertController.textFields?.first?.text)!, cell: cell)
        }
        let cancelAction = UIAlertAction(title: "取消", style: .default) { (action) in
        }
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        present(alertController, animated: true, completion: nil)
    }
    func updateAreaAlert(cell:MyDetailTableViewCell){
        let alertController = UIAlertController(title: "选择地区", message: nil, preferredStyle: .alert)
        alertController.addTextField { (text) in
            
        }
        alertController.textFields?.first?.inputView = pickerView
        //        textAlertController.textFields?.first?.keyboardType = .default
        weak var weakSelf:MyDetailTableViewController? = self
        let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
            weakSelf?.myDetailModel.area = (alertController.textFields?.first?.text)!
            // 给 nickname 写 willset：把修改信息发给 lcode属性
            //            通知临时模型，页面离开时候比较两个模型，不同的话就对应上传
//            weakSelf?.myDetailModelTemp.area = (weakSelf?.myDetailModel.area)!
            weakSelf?.setCellRightLabel(property: (alertController.textFields?.first?.text)!, cell: cell)
        }
        let cancelAction = UIAlertAction(title: "取消", style: .default) { (action) in
        }
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        areaAlertController = alertController
        present(alertController, animated: true, completion: nil)
    }
    func setTableView(){
        tableView.register(MyDetailTableViewCell.self, forCellReuseIdentifier: "MyDetailTableViewCell")
        tableView.dataSource = self
        tableView.delegate = self
    }
    func setPickerView(){
        pickerView.dataSource = self
        pickerView.delegate = self
        pickerView.autoresizingMask=[.flexibleWidth,.flexibleBottomMargin]
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source
    override func viewWillAppear(_ animated: Bool) {
        navigationController?.navigationBar.setBackgroundColor(.APP)
        navigationController?.navigationBar.titleTextAttributes = (naviBarTitleAttributes as! [NSAttributedStringKey : Any])
        makeReturnButton()
    }
    func makeReturnButton(){
        let leftButtonView = UIView(frame: CGRect(x: 0, y: 0, width: 60, height: 40))
        let leftButton = UIButton(type: .system)
        leftButton.backgroundColor = .clear
        leftButton.frame = leftButtonView.frame
        leftButton.setImage(UIImage(named:"左侧返回"), for: .normal)
        leftButton.setTitle(RETURNBUTTONTITLEMARGIN+"我的", for: .normal)
        leftButton.tintColor = .white
        leftButton.autoresizesSubviews = true
        leftButton.contentHorizontalAlignment = .left
        leftButton.autoresizingMask = UIViewAutoresizing(rawValue: (UIViewAutoresizing.flexibleWidth.rawValue | UIViewAutoresizing.flexibleLeftMargin.rawValue))
        
        leftButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: -15, bottom: 0, right: 0)
        leftButton.addTarget(self, action: #selector(backNative), for: .touchUpInside)
        leftButtonView.addSubview(leftButton)
        let leftBarButton = UIBarButtonItem(customView: leftButtonView)
        navigationItem.leftBarButtonItem = leftBarButton
    }
    @objc func backNative(){
        navigationController?.dismiss(animated: true, completion: nil)
    }
    override func numberOfSections(in tableView: UITableView) -> Int {
        return cellLabelGroups.count
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        
        return cellLabelGroups[section].count
    }
    

    
    
    func setCellRightLabel(property:String,cell:MyDetailTableViewCell?){
        cell?.rightLabel.text = (property == "") ? rightLabelPlaceholder : property
        cell?.rightLabel.textColor = (cell?.rightLabel.text == rightLabelPlaceholder) ? .LabelFontPlaceHolder : .black
        cell?.addSubview((cell?.rightLabel)!)
    }
    
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var cell:MyDetailTableViewCell? = tableView.dequeueReusableCell(withIdentifier: "MyDetailTableViewCell") as! MyDetailTableViewCell
        if(cell==nil){
            cell = MyDetailTableViewCell(style: .default, reuseIdentifier: "MyDetailTableViewCell")
        }
        cell?.textLabel?.text = cellLabelGroups[indexPath.section][indexPath.row]
        cell?.textLabel?.textAlignment = .left
        
        switch (indexPath.section,indexPath.row) {
        case (0,0):
            cell?.hiddenHeadImage = false
            cell?.addSubview((cell?.headImageView)!)
        case (0,1):
        setCellRightLabel(property: myDetailModel.nickName, cell: cell)
        case (0,2):
            setCellRightLabel(property: judgeGender(gender:myDetailModel.gender!), cell: cell)
        case (0,3):
            setCellRightLabel(property: myDetailModel.qq, cell: cell)
        case (1,0):
            setCellRightLabel(property: judgeBirthday(birthday:myDetailModel.birthday), cell: cell)
        case (1,1):
            setCellRightLabel(property: myDetailModel.area, cell: cell)
        default: break
    }
        return cell!
        
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath) as! MyDetailTableViewCell
        switch (indexPath.section,indexPath.row) {
        case (0,0):let imagePickerController = UIImagePickerController()
            imagePickerController.sourceType = .photoLibrary
//            需要图片编辑就打开这句
//            imagePickerController.allowsEditing = true
            imagePickerController.delegate = self
//        相册的代理是这个类 self，不能使用 navigationcontroller，应该分别使用 self 的 present 和 dismiss 进行跳转
            present(imagePickerController, animated: true, completion: nil)
        case (0,1):
            updateNicknameAlert(cell:cell)
            //弹框填写昵称
        case (0,2):updateGenderAlert(cell: cell)
            //弹出 pickerview 男女
        pickerView.tag = 0
        case (0,3):updateQQAlert(cell: cell)
            //弹框填写QQ
        case (1,0):updateBirthdayAlert(cell: cell)
            //pickerview 生日
        case (1,1):updateAreaAlert(cell: cell)
        pickerView.tag = 1
            //pickerview 省市
            pickerView.tag = 1
        default: break
        }
    }
    func judgeGender(gender:Gender) -> String{
        switch gender {
        case .male:
            return "男"
        case .female:
            return "女"
        case .unknown:
            return rightLabelPlaceholder
        }
    }
    func judgeBirthday(birthday:Birthday) -> String{
        if(birthday.year == ""){
         return rightLabelPlaceholder
        }
        return birthday.year+"-"+birthday.month+"-"+birthday.day
    }
    @objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        let type = info[UIImagePickerControllerMediaType] as! String
        if (type == "public.image"){
            let image = fixOrientation(aImage: info[UIImagePickerControllerOriginalImage] as! UIImage)
////            let data = UIImageJPEGRepresentation(image, 0.5)
//            let data = UIImagePNGRepresentation(image)
////            let docunentsPath = NSHomeDirectory().appending("Documents")
////            let fileManager = FileManager.default
////            try! fileManager.createDirectory(atPath: docunentsPath, withIntermediateDirectories: true, attributes: nil)
////            fileManager.createFile(atPath: docunentsPath+"/image.png", contents: data, attributes: nil)
////            let filePath = docunentsPath + "/image.png"
//            let homeDirectory = NSHomeDirectory()
//            let documentPath = homeDirectory + "/Documents"
//            let fileManager = FileManager.default
//            do{
//                try fileManager.createDirectory(atPath: documentPath, withIntermediateDirectories: true, attributes: nil)
//            }
//            catch let error{
//
//            }
//            fileManager.createFile(atPath: documentPath.appending("/image.png"), contents: data, attributes: nil)
//            let filePath = String(format: "%@%@", documentPath,"/image.png")
//            print("filePath:"+filePath)
//            Utils.AlamofireAsynchronousUploadImage(headImage: image, callBack: { (image) in
//                print("上传图片")
//            })
            currentHeadImage = image
            myDetailModel.headImg = image
            tableView.reloadData()
        }
            //            接下来开始上传图片
        
                //        var iv = UIImageView(frame: view.bounds)
        //    UIImagePickerControllerEditedImage 编辑后的图片
        //    UIImagePickerControllerOriginalImage 原始图片
//        iv.image = info[UIImagePickerControllerOriginalImage] as! UIImage
//        view.addSubview(iv)
        
        //返回页面
        dismiss(animated: true, completion: nil)

    }
    func fixOrientation(aImage: UIImage) -> UIImage {
        // No-op if the orientation is already correct
        if aImage.imageOrientation == .up {
            return aImage
        }
        // We need to calculate the proper transformation to make the image upright.
        // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
//        var transform: CGAffineTransform = CGAffineTransformIdentity
        var transform:CGAffineTransform = .identity
        switch aImage.imageOrientation {
        case .down, .downMirrored:
//            transform = CGAffineTransform.Translate(transform, aImage.size.width, aImage.size.height)
            transform = transform.translatedBy(x: aImage.size.width, y: aImage.size.height)
            transform = transform.rotated(by: CGFloat(M_PI))
        case .left, .leftMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0)
            transform = transform.translatedBy(x: aImage.size.width, y: 0)
//            transform = CGAffineTransformRotate(transform, CGFloat(M_PI_2))
            transform = transform.rotated(by: CGFloat(M_PI_2))
        case .right, .rightMirrored:
//            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height)
            transform = transform.translatedBy(x: 0, y: aImage.size.height)
//            transform = CGAffineTransformRotate(transform, CGFloat(-M_PI_2))
            transform = transform.rotated(by: CGFloat(-M_PI_2))
        default:
            break
        }
        
        switch aImage.imageOrientation {
        case .upMirrored, .downMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0)
            transform = transform.translatedBy(x: aImage.size.width, y: 0)
//            transform = CGAffineTransformScale(transform, -1, 1)
            transform = transform.scaledBy(x: -1, y: 1)
        case .leftMirrored, .rightMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0)
            transform = transform.translatedBy(x: aImage.size.height, y: 0)
//            transform = CGAffineTransformScale(transform, -1, 1)
            transform = transform.scaledBy(x: -1, y: 1)
        default:
            break
        }
        
        // Now we draw the underlying CGImage into a new context, applying the transform
        // calculated above.
        
        
        //这里需要注意下CGImageGetBitmapInfo，它的类型是Int32的，CGImageGetBitmapInfo(aImage.CGImage).rawValue，这样写才不会报错
//        let ctx: CGContext = CGContext(data: nil, width: Int(aImage.size.width), height: Int(aImage.size.height), bitsPerComponent: CGImage.bitsPerComponent(aImage.cgImage!), bytesPerRow: 0, space: CGImageGetColorSpace(aImage.cgImage!)!, bitmapInfo: CGImageGetBitmapInfo(aImage.cgImage!).rawValue)!
        let ctx = CGContext(data: nil, width: Int(aImage.size.width), height: Int(aImage.size.height), bitsPerComponent: (aImage.cgImage!).bitsPerComponent, bytesPerRow: 0, space: (aImage.cgImage!).colorSpace!, bitmapInfo: (aImage.cgImage!).bitmapInfo.rawValue)
        ctx!.concatenate(transform)
        switch aImage.imageOrientation {
        case .left, .leftMirrored, .right, .rightMirrored:
            // Grr...
//            CGContextDrawImage(ctx, CGRectMake(0, 0, aImage.size.height, aImage.size.width), aImage.cgImage)
            ctx?.draw(aImage.cgImage!, in: CGRect(x: 0, y: 0, width: aImage.size.height, height: aImage.size.width))
        default:
//            CGContextDrawImage(ctx, CGRectMake(0, 0, aImage.size.width, aImage.size.height), aImage.CGImage)
            ctx?.draw(aImage.cgImage!, in: CGRect(x: 0, y: 0, width: aImage.size.width, height: aImage.size.height))
        }
        
        // And now we just create a new UIImage from the drawing context
        let cgimg: CGImage = ctx!.makeImage()!
        let img = UIImage(cgImage: cgimg)
        return img
    }
  

    /*
    // Override to support editing the table view.
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            // Delete the row from the data source
            tableView.deleteRows(at: [indexPath], with: .fade)
        } else if editingStyle == .insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

